<?php

namespace plugin\admin\app\model;

use plugin\admin\app\model\Base;

/**
 * @property integer $id ID(主键)
 * @property string $username 用户名
 * @property string $nickname 昵称
 * @property string $password 密码
 * @property string $avatar 头像
 * @property string $email 邮箱
 * @property string $mobile 手机
 * @property string $created_time 创建时间
 * @property string $updated_time 更新时间
 * @property string $login_at 登录时间
 * @property string $roles 角色
 * @property integer $status 状态 0正常 1禁用
 */
class Admin extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_admins';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    protected $appends=[
        'role_key'
    ];
     public function getRoleKeyAttribute($value): string
     {
         $role_key = "null";
         $user_id = $this->id;
         if ($user_id){
             $role_id = AdminRole::where('admin_id',$user_id)->value('role_id');
             if ($role_id){
                 $role_key = Role::where('id',$role_id)->value('role_key')??"null";
             }
         }
         return $role_key;
     }

}
